<template>
	<view class="content">
		<view class="input-group">
			<view class="input-row">
				<text class="title">昵称：</text>
				<m-input type="text" clearable v-model="nickname" placeholder="请输入昵称"></m-input>
			</view>
			<view class="input-row border">
				<text class="title">账号：</text>
				<m-input type="text" focus clearable v-model="user" placeholder="请输入账号"></m-input>
			</view>
			<view class="input-row border">
				<text class="title">密码：</text>
				<m-input type="password" displayable v-model="password" placeholder="请输入密码"></m-input>
			</view>
			<view class="input-row border">
				<text class="title">确定密码：</text>
				<m-input type="password" displayable v-model="passwordtwo" placeholder="请再次输入密码"></m-input>
			</view>
		
		</view>
		<view class="btn-row">
			<button type="primary" class="primary" @tap="register">注册</button>
		</view>
	</view>
</template>

<script>
	import service from '../../service.js';
	import mInput from '../../components/m-input.vue';

	export default {
		components: {
			mInput
		},
		data() {
			return {
				user: '',
				password: '',
				nickname: '',
				passwordtwo:''
			}
		},
		methods: {
			register() {
				/**
				 * 客户端对账号信息进行一些必要的校验。
				 * 实际开发中，根据业务需要进行处理，这里仅做示例。
				 */
					
				if (this.user.length < 5) {
					uni.showToast({
						icon: 'none',
						title: '账号最短为 5 个字符'
					});
					return;
				}
				if (this.password.length < 6) {
					uni.showToast({
						icon: 'none',
						title: '密码最短为 6 个字符'
					});
					return;
				}
				console.log("??")
				if (this.passwordtwo != this.password) {
					uni.showToast({
						icon: 'none',
						title: '两次输入密码不一致'
					});
					return;
				}

				// const data = {
				// 	account: this.account,
				// 	password: this.password,
				// 	email: this.email
				// }
				
				uni.request({
				    url: "http://localhost:5005/admin/nottoken/registered", //仅为示例，并非真实接口地址。
					method:"POST",
				    data: {
					   nickname:this.nickname,
				       user: this.user,
				       password: this.password,
					   passwordtwo:this.passwordtwo
				    },
				    success: function (res) {
				        console.log(res,"res");
						
						uni.navigateTo({
						    url: '/pages/login/login'
						});
					
						uni.showToast({
							title: res.data.msg
						});
				    }
				});
				
				// service.addUser(data);
				
				// uni.navigateBack({
				// 	delta: 1
				// });
			}
		}
	}
</script>

<style>

</style>
